package homework.view;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import homework.entity.User;
import homework.service.Usermanage;

public class C1Frame extends JFrame{
	private JLabel l_name,l_id,l_kilometer, l_weigth, l_type,l_origin,l_sender,l_recipient,l_destination;
    private JTextField t_id, t_kilometer, t_weigth, t_type,t_origin,t_sender,t_recipient,t_destination;
    private JButton b_send, b_reset;
	public C1Frame(){
	    	
	        this.setTitle("快递物流平台-后台投递页面(C1)");
	        setSize(400,500);
	    	setLocation(800,200);;
	        init();
	        this.setVisible(true);
	
	}
	
	public void init(){
        this.setLayout(null);
        
        Font font = new Font("宋体", Font.PLAIN, 30);
        l_name = new JLabel("包裹登记");
        l_name.setFont(font);
        
	    l_id = new JLabel("编号",(int)CENTER_ALIGNMENT);
	    t_id = new JTextField();
	    l_kilometer = new JLabel("千里数",(int)CENTER_ALIGNMENT);
	    t_kilometer = new JTextField();
	    l_weigth = new JLabel("重量",(int)CENTER_ALIGNMENT);
	    t_weigth = new JTextField();
	    l_type = new JLabel("类型：（//1普通 2加急 3轻放）",(int)CENTER_ALIGNMENT);
	    t_type = new JTextField();
	    l_origin = new JLabel("始发地",(int)CENTER_ALIGNMENT);
	    t_origin = new JTextField();
	    l_sender = new JLabel("寄件人",(int)CENTER_ALIGNMENT);
	    t_sender = new JTextField();
	    l_recipient = new JLabel("收件人",(int)CENTER_ALIGNMENT);
	    t_recipient = new JTextField();
	    l_destination = new JLabel("目的地",(int)CENTER_ALIGNMENT);
	    t_destination = new JTextField();
	    
	    b_reset = new JButton("重置");
	    b_reset.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				t_id.setText("");
				t_kilometer.setText("");
				t_sender.setText("");
				t_recipient.setText("");
				t_destination .setText("");
				t_weigth.setText("");
				t_origin .setText("");
				t_type.setText("");
			}
		});
	    b_send = new JButton("登记");
	    b_send.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				String s2;
				Usermanage um = new Usermanage();
				int f = um.packagecreate(t_sender.getText(),t_id.getText(), t_kilometer.getText(), t_weigth.getText(), t_type.getText(),t_origin.getText(),t_recipient.getText(),t_destination.getText());
				if(f==1) {
					JOptionPane.showMessageDialog(null, "操作成功");
				}
				
			}
		});
	    JPanel p= new JPanel(new GridLayout(1,1,5,5));
	    p.add(l_name);
	    add(p);
	    
	    p= new JPanel(new GridLayout(10,2,5,5));
	    p.add(l_id);
    	p.add(t_id);
    	p.add(l_kilometer);
    	p.add(t_kilometer);
    	p.add(l_weigth);
    	p.add(t_weigth);
    	p.add(l_type);
    	p.add(t_type);
    	p.add(l_destination);
    	p.add(t_destination);
    	p.add(l_origin);
    	p.add(t_origin);
    	p.add(l_recipient);
    	p.add(t_recipient);
    	p.add(l_sender);
    	p.add(t_sender);
    	p.add(b_reset);
    	p.add(b_send);
    	p.setBounds(5,5,375,480);
    	add(p);
	}
	

}
